<template>
  <div class="container">
    <div class="wrap_box">
      <div class="title">
        <i class="shu"></i>
        <span>当前跟进状态 [{{sanqi}}]</span>
      </div>
      <div class="body">
        <div class="flex">
          <span class="flex-item">服务期时长</span>
          <span>{{sanqiinfo.fuwuqi}}天</span>
        </div>
        <div class="flex">
          <span class="flex-item">铺垫期时长</span>
          <span>{{sanqiinfo.pudianqi}}天</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import wx from 'wx'
import api from '@/utils/api'
import Toast from '@/utils/toast'
export default {
  data () {
    return {
      guest_id: '',
      sanqi: '',
      sanqiinfo: ''
    }
  },
  components: {
  },
  async onLoad () {
    const that = this
    // 接收客户id
    that.guest_id = that.$route.query.id
    that.get_info()
  },
  methods: {
    async get_info () {
      const that = this
      const userInfo = wx.getStorageSync('userInfo')
      const res = await api.getguestsanqi({
        guest_id: that.guest_id,
        orcode: userInfo['orcode']
      })
      if (res.code === '100') {
        const nowtime = Math.round(Date.now() / 1000)
        const arrivetime = res.data[0].arrivetime
        const fuwuqi = res.sanqi.fuwuqi
        let sanqi = ''
        if (nowtime < (arrivetime + 86400 * fuwuqi)) {
          sanqi = '服务期'
        } else if ((arrivetime + 86400 * fuwuqi) < nowtime && nowtime < (arrivetime + 86400 * fuwuqi + 86400 * res.sanqi.pudianqi)) {
          sanqi = '铺垫期'
        } else {
          sanqi = '销售期'
        }
        that.sanqi = sanqi
        that.sanqiinfo = res.sanqi
      } else {
        Toast(res.msg, 'noicon')
      }
    }
  }
}
</script>

<style scoped>
.wrap_box {
  width: 100%;
  box-shadow: 0 6rpx 20rpx rgba(255, 68, 68, 0.1);
  background-color: rgba(255, 255, 255, 1);
  margin-bottom: 18rpx;
}
.wrap_box .title {
  padding: 28rpx 0 28rpx 34rpx;
  font-size: 32rpx;
  font-weight: bold;
  color: rgba(51, 51, 51, 1);
}
.wrap_box .body {
  padding-left: 48rpx;
}
.wrap_box .body > div {
  height: 80rpx;
  padding-right: 46rpx;
  font-size: 28rpx;
  color: rgba(102, 102, 102, 1);
  border-bottom: 2rpx solid rgba(153, 153, 153, 0.1);
}
.wrap_box .body > div:last-child {
  border-bottom: none;
}
.shu {
  display: inline-block;
  width: 4rpx;
  height: 20rpx;
  background: rgba(255, 68, 68, 1);
  border-radius: 2rpx;
  margin-right: 12rpx;
}
</style>